<?php
namespace App\Models;

use App\Libraries\msg\Push;
class Message extends CommonModel {
    protected $table = 'client_user_messages_list';
	private function getPushType($key)
    {
        return self::where(['key'=>$key])->first();
    }
    /**
     * 推送控制
     * @param $id int 店铺ID或用户ID
     * @param $key string 类型
     * @param $connect string 消息描述
     * @param $data string 参数
     * @return true
     */
	public function message_push($id,$key,$connect,$data,$id_type=0){
	    $date =self::getPushType($key);

	    if(!$date){
	        return false;
        }
        if($id_type==1){
	        $uid = ShopStore::getStoreUid($id);
        }else{
            $uid=$id;
        }
        $param=array();
        $param['type']=$date->type_name;
        $param['is_send']=$date->is_send;
        $param['messages_type_id']=$date->messages_type_id;
        $param['sound'] = $date->sound;
        $param[$date->param_name]=$data;
        $push = new Push();
        $push->queue($uid,$date->title,$connect,$param);
        return true;
    }
}